public class SeqList {
    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        int flag = m + n - 1;
        int i = m - 1;
        int j = n - 1;
        while (i != 0 || j != 0) {
            while (nums1[i] >= nums2[j] && i > 0) {
                nums1[flag--] = nums1[i];
                i--;
            }
            while (nums2[j] >= nums1[i] && i > 0) {
                nums1[flag--] = nums2[j];
                j--;
            }
        }
        while (i > 0) {
            nums1[flag--] = nums1[i];
            i--;
        }
        while (j > 0) {
            nums1[flag--] = nums2[j];
            j--;
        }
    }


    public static void main(String[] args) {
        int[] arr1 = {1,2,3,0,0,0};
        int m = 3;
        int[] arr2 = {2,5,6};
        int n = 3;
        merge(arr1,m,arr2,n);
        for (int i = 0; i < arr1.length; i++) {
            System.out.print(arr1[i] + " ");
        }
    }
}
